package eu.jpereira.trainings.designpatterns.structural.decorator.channel.decorator;

import java.util.ArrayList;

import eu.jpereira.trainings.designpatterns.structural.decorator.channel.SocialChannel;




public class WordCensor extends SocialChannelDecorator {

	
	
	ArrayList<String> cewords;
	   
    public WordCensor(ArrayList<String> cewords){
    	 this.cewords = cewords;
    }
    
    
    public WordCensor(ArrayList<String> cewords, SocialChannel channel) {
    	this.cewords = cewords;
		this.delegate = channel;
	}
	@Override
	public void deliverMessage(String message) {
		for(int i=0; i< cewords.size(); i++ ) {
			StringBuilder builder = new StringBuilder();
			builder.append(message.substring(0,message.indexOf(cewords.get(i)) ));
			builder.append("***");
			builder.append(message.substring(   message.indexOf(cewords.get(i)) + cewords.get(i).length() ));
			message = builder.toString();
		}
		
		
		
		delegate.deliverMessage(message);

	}

}
